package com.mf.morefun.ui;

import android.Manifest;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.provider.Settings;
import android.support.annotation.NonNull;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;
import com.apkfuns.logutils.LogUtils;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.Target;
import com.mf.morefun.MoreFunApplication;
import com.mf.morefun.R;
import com.mf.morefun.base.BaseBusActivity;
import com.mf.morefun.bean.AliInfoBean;
import com.mf.morefun.bean.BannerBean;
import com.mf.morefun.bean.LoginBean;
import com.mf.morefun.bean.PMUserBean;
import com.mf.morefun.bean.ResultBean;
import com.mf.morefun.constant.Configuration;
import com.mf.morefun.requestbean.RequesBannerBean;
import com.mf.morefun.requestbean.RequestLoginBean;
import com.mf.morefun.ui.dohomework.HomeworkListActivity;
import com.mf.morefun.ui.gifts.GiftsListActivity;
import com.mf.morefun.ui.grindingears.GrindingEarsActivity;
import com.mf.morefun.ui.moreread.MoreReadingActivity;
import com.mf.morefun.ui.myclass.ClassListActivity;
import com.mf.morefun.ui.person.MineInfoActivity;
import com.mf.morefun.ui.personnelmanagement.PersonnelManagementActivity;
import com.mf.morefun.ui.userinfo.LoginActivity;
import com.mf.morefun.util.PermissionsChecker;
import com.mf.morefun.util.StorageUtil;
import com.mf.morefun.widget.NetErrorPop;
import com.mf.morefun.widget.RoundProcessDialog;
import com.mf.morefun.widget.TransformationHomeUtils;
import com.zhcx.zhcxlibrary.utils.AppManager;
import com.zhcx.zhcxlibrary.utils.DateUtils;
import com.zhcx.zhcxlibrary.utils.FileUtils;
import com.zhcx.zhcxlibrary.utils.SPUtils;
import com.zhcx.zhcxlibrary.utils.StringUtils;
import com.zhcx.zhcxlibrary.utils.ToastUtils;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.jetbrains.annotations.Nullable;
import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

import static android.support.constraint.Constraints.TAG;

public class HomePagerActivity extends BaseBusActivity {
    @BindView(R.id.vp_home)
    ViewPager vpHome;
    @BindView(R.id.ll_content)
    LinearLayout llContent;
    @BindView(R.id.iv_personhead)
    ImageView ivPersonhead;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.ll_person)
    LinearLayout llPerson;
    @BindView(R.id.ll_homework)
    LinearLayout llHomework;
    @BindView(R.id.ll_libray)
    LinearLayout llLibray;
    @BindView(R.id.ll_listen)
    LinearLayout llListen;
    @BindView(R.id.ll_gifts)
    LinearLayout llGifts;
    @BindView(R.id.ll_class)
    LinearLayout llClass;
    @BindView(R.id.ll_personnel_management)
    LinearLayout llPersonnelManagement;
    private SPUtils mSputils;
    private List<View> viewContains = new ArrayList<View>();//viewpager容器
    private int currentPosition = 0;
    private MyPagerAdapter myPagerAdapter;
    private RoundProcessDialog dialog;
    //这个页面所需要权限列表
    private String[] permission = new String[]{ Manifest.permission.RECORD_AUDIO,
            Manifest.permission.INTERNET,
            Manifest.permission.ACCESS_NETWORK_STATE,
            Manifest.permission.CHANGE_WIFI_STATE,
            Manifest.permission.ACCESS_WIFI_STATE,
            Manifest.permission.RECEIVE_BOOT_COMPLETED,
            Manifest.permission.VIBRATE,
            Manifest.permission.CAMERA,
            Manifest.permission.WAKE_LOCK,
            Manifest.permission.WRITE_EXTERNAL_STORAGE,
            Manifest.permission.READ_EXTERNAL_STORAGE};
    private static final int REQUEST_CODE = 0; // 请求码

    @Override
    protected int getNaviteColor() {
        return 0;
    }

    @Override
    protected int getContentLayoutId() {
        return R.layout.activity_homepager;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        mSputils = new SPUtils(getApplicationContext());
        tvName.setText(mSputils.getString(Configuration.USERPHONE));
        dialog = new RoundProcessDialog(HomePagerActivity.this, "");
        EventBus.getDefault().register(this);
    }

    @Override
    protected void initData() {
//        if (IsLoginBean.isNo(true)) {
        initLogin(mSputils.getString(Configuration.USERPHONE), mSputils.getString(Configuration.USERPASSWORD));
        //获取阿里云授权接口
        initGetAliInfo();
    }

    //接受musicService发过来的消息
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void getMusicMessage(String message) {
        if (message.equals("LOGOUT")){
            backLogin();
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    private class mRequestListener implements RequestListener {
        private ImageView ivPersonhead;

        public mRequestListener(ImageView ivPersonhead) {
            this.ivPersonhead = ivPersonhead;
        }

        @Override
        public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) {
            Log.d(TAG, "onException: " + e.toString() + "  model:" + model + " isFirstResource: " + isFirstResource);
            Message msg = new Message();
            msg.what = 100;
            msg.obj = ivPersonhead;
            mHandler.sendMessage(msg);
            return false;
        }

        @Override
        public boolean onResourceReady(Object resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) {
            Log.e(TAG, "model:" + model + " isFirstResource: " + isFirstResource);
            return false;
        }
    }

    ;


    private void isHaveMenu() {
        if (null != MoreFunApplication.loginBean.getResult().getOrgan()) {
            initGetBanner();
        } else {
            showViewpager(null);
        }
        if (StringUtils.isEmpty(MoreFunApplication.loginBean.getResult().getUserType())) {
            llPersonnelManagement.setVisibility(View.GONE);
            llHomework.setVisibility(View.VISIBLE);
            llGifts.setVisibility(View.VISIBLE);
        } else {
            if (MoreFunApplication.loginBean.getResult().getUserType().equals("1")) {//1学员
                llPersonnelManagement.setVisibility(View.GONE);
                llHomework.setVisibility(View.VISIBLE);
                llGifts.setVisibility(View.VISIBLE);
            } else if (MoreFunApplication.loginBean.getResult().getUserType().equals("2")) {//2老师
                llPersonnelManagement.setVisibility(View.GONE);
                llHomework.setVisibility(View.GONE);
                llGifts.setVisibility(View.GONE);
            } else if (MoreFunApplication.loginBean.getResult().getUserType().equals("3")) {//3管理员
                llPersonnelManagement.setVisibility(View.VISIBLE);
                llHomework.setVisibility(View.GONE);
                llGifts.setVisibility(View.GONE);
            }
        }
    }

    private void initGetAliInfo() {
        RequestParams params = new RequestParams(Configuration.HOST + Configuration.GETALIINFOV2);

        PMUserBean.CountryBean countrybean = new PMUserBean.CountryBean();

        if( MoreFunApplication.loginBean.getResult().getCountry() != null)
        {
            countrybean.setId( MoreFunApplication.loginBean.getResult().getCountry().getId());
        }
        else
        {
            countrybean.setId("0");
        }

        params.setBodyContent(JSON.toJSONString(countrybean));

        x.http().post(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                if (!StringUtils.isEmpty(result)) {
                    AliInfoBean aliInfoBean = JSON.parseObject(result, AliInfoBean.class);
                    if (aliInfoBean.getStatusCode() == 200) {
                        mSputils.putString(Configuration.ACCESSKEYID, aliInfoBean.getAccessKeyId());
                        mSputils.putString(Configuration.ACCESSKEYSECRET, aliInfoBean.getAccessKeySecret());
                        mSputils.putString(Configuration.SECURITYTOKEN, aliInfoBean.getSecurityToken());

                        mSputils.putString(Configuration.ENDPOINT, aliInfoBean.getEndPoint());
                        mSputils.putString(Configuration.BUCKETNAME, aliInfoBean.getBucketName());
                        mSputils.putString(Configuration.BUCKETDOMAIN, aliInfoBean.getBucketDomain());
                    }
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {

            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {

            }
        });
    }
    private final int REQUEST_STORAGE = 100;
    @Override
    protected void onResume() {
        super.onResume();
        //这里检测权限
        checkAllPermission();
        if (null != MoreFunApplication.loginBean) {
            tvName.setText(MoreFunApplication.loginBean.getResult().getName());
            showCicleImg();
        }
    }
private PermissionsChecker permissionsChecker;
    private void checkAllPermission() {
        if (android.os.Build.VERSION.SDK_INT >= 23 && android.os.Build.VERSION.SDK_INT < 26) {
            permissionsChecker = new PermissionsChecker(HomePagerActivity.this);
            if (permissionsChecker.lacksPermissions(permission)) {
                showMissingPermissionDialog();
            }
        }else if(android.os.Build.VERSION.SDK_INT >= 26){
            //检测存储权限
            if (!StorageUtil.writeStorage() || !StorageUtil.readStorage()){
                showMissingPermissionDialog();
            }
        }
    }

    // 显示缺失权限提示
    private void showMissingPermissionDialog() {
        AlertDialog.Builder builder = new AlertDialog.Builder(HomePagerActivity.this);
        builder.setTitle(R.string.help);
        builder.setMessage(R.string.string_help_text);

        // 拒绝, 退出应用
        builder.setNegativeButton(R.string.quit, new DialogInterface.OnClickListener() {
            @Override public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        });

        builder.setPositiveButton(R.string.settings, new DialogInterface.OnClickListener() {
            @Override public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                startAppSettings();
            }
        });
        builder.show();
    }

    // 启动应用的设置
    private void startAppSettings() {
        Intent localIntent = new Intent();
        localIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (Build.VERSION.SDK_INT >= 9) {
            localIntent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
            localIntent.setData(Uri.fromParts("package", getPackageName(), null));
        } else if (Build.VERSION.SDK_INT <= 8) {
            localIntent.setAction(Intent.ACTION_VIEW);
            localIntent.setClassName("com.android.settings", "com.android.setting.InstalledAppDetails");
            localIntent.putExtra("com.android.settings.ApplicationPkgName", getPackageName());
        }
        startActivity(localIntent);
    }

    private boolean isSuccess = false;

    private void showCicleImg() {
        CircleCrop circleCrop = new CircleCrop();
        RequestOptions options = RequestOptions.bitmapTransform(circleCrop);
        Glide.with(HomePagerActivity.this).asBitmap().load(MoreFunApplication.loginBean.getResult().getHeadPortrait()).listener(new mRequestListener(ivPersonhead)).apply(options).into(new TransformationHomeUtils(ivPersonhead, HomePagerActivity.this));
    }

    private void initLogin(String user, String password) {
        if (null != dialog && !dialog.isShow()){
            dialog.show();
        }
        RequestParams params = new RequestParams(Configuration.HOST + Configuration.LOGIN);
        RequestLoginBean bean = new RequestLoginBean();
        bean.setPhone(user);
        bean.setPassword(FileUtils.md5(password));
        params.setBodyContent(JSON.toJSONString(bean));
        params.setCharset("UTF-8");
        params.addHeader("Content-Type", "application/json");
        params.setConnectTimeout(10000);
        x.http().post(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                if (null != dialog && dialog.isShow()){
                    dialog.cancel();
                }
                LogUtils.d(result);
                if (!StringUtils.isEmpty(result)) {
                    MoreFunApplication.loginBean = JSON.parseObject(result, LoginBean.class);
                    if (MoreFunApplication.loginBean.getErrorCode() == 0) {
                        try {
                            if (MoreFunApplication.loginBean.getResult().getEnableEnd().length() == 10){
                                long enableTime = DateUtils.DEFAULT_DATE_FORMAT.parse(MoreFunApplication.loginBean.getResult().getEnableEnd() + " 23:59:59").getTime();
                                long currentTime = System.currentTimeMillis();
                                if (enableTime >= currentTime) {
                                    tvName.setText(MoreFunApplication.loginBean.getResult().getName());
                                    showCicleImg();
                                    isHaveMenu();
                                } else {
                                    backLogin();
                                    ToastUtils.show(getApplicationContext(), "账号已过期", 100);
                                }
                            }else {
                                long enableTime = DateUtils.DEFAULT_DATE_FORMAT.parse(MoreFunApplication.loginBean.getResult().getEnableEnd()).getTime();
                                long currentTime = System.currentTimeMillis();
                                if (enableTime >= currentTime) {
                                    tvName.setText(MoreFunApplication.loginBean.getResult().getName());
                                    showCicleImg();
                                    isHaveMenu();
                                } else {
                                    backLogin();
                                    ToastUtils.show(getApplicationContext(), "账号已过期", 100);
                                }
                            }
                        }catch (Exception e){
                            e.printStackTrace();
                            backLogin();
                            ToastUtils.show(getApplicationContext(), "账号已过期", 100);
                        }
                    } else {
                        backLogin();
                        ToastUtils.show(getApplicationContext(), "账号已过期", 100);
                    }
                } else {
                    backLogin();
                    ToastUtils.show(getApplicationContext(), "账号已过期", 100);
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                if (null != dialog && dialog.isShow()){
                    dialog.cancel();
                }
                backLogin();
                ToastUtils.show(getApplicationContext(), "账号已过期", 100);
            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {

            }
        });
    }

    //返回登陆页面
    private void backLogin() {
        try {
            ToastUtils.show(getApplicationContext(), "账号已过期", 100);
            AppManager.getAppManager().finishAllActivity();
            mSputils.putString(Configuration.USERID, "");
            Intent mIntent = new Intent(HomePagerActivity.this, LoginActivity.class);
            startActivity(mIntent);
            finish();
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    private void initGetBanner() {
        RequestParams params = new RequestParams(Configuration.HOST + Configuration.HOMEBIANNER);
        RequesBannerBean bannerBean = new RequesBannerBean();
        RequesBannerBean.OrganBean organBean = new RequesBannerBean.OrganBean();
        organBean.setId(MoreFunApplication.loginBean.getResult().getOrgan().getId());
        bannerBean.setOrgan(organBean);
        params.setBodyContent(JSON.toJSONString(bannerBean));
        params.setCharset("UTF-8");
        params.addHeader("Content-Type", "application/json");
        params.setConnectTimeout(10000);
        x.http().post(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                LogUtils.d(result);
                if (!StringUtils.isEmpty(result)) {
                    ResultBean resultBean = JSON.parseObject(result, ResultBean.class);
                    if (resultBean.getErrorCode() == 0) {
                        if (!StringUtils.isEmpty(resultBean.getResult())) {
                            List<BannerBean> bannerBeanList = JSON.parseArray(resultBean.getResult(), BannerBean.class);
                            showViewpager(bannerBeanList);
                        } else {
                            showViewpager(null);
                        }
                    } else {
                        showViewpager(null);
                    }
                } else {
                    showViewpager(null);
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                showViewpager(null);
                mHandler.sendEmptyMessage(101);
            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {

            }
        });
    }

    //展示viewpager
    private void showViewpager(List<BannerBean> bannerBeanList) {
        viewContains.clear();
        currentPosition = 0;
//        vpHome.setPageTransformer(true, new MyPageTransform());
        setPagerAdapter();
        setPagerListener();
        if (null != deleteNoPic(bannerBeanList) && deleteNoPic(bannerBeanList).size() > 0) {
            for (int i = 0; i < deleteNoPic(bannerBeanList).size(); i++) {
                View view = LayoutInflater.from(HomePagerActivity.this).inflate(R.layout.layout_mainadvertisement, null);
                ImageView imageView = view.findViewById(R.id.iv_image);
                Glide.with(getApplicationContext()).load(deleteNoPic(bannerBeanList).get(i).getCover()).into(imageView);
                viewContains.add(view);
            }
            myPagerAdapter.notifyDataSetChanged();
            if (deleteNoPic(bannerBeanList).size() > 1) {
                if (mHandler.hasMessages(0)) {
                    mHandler.removeMessages(0);
                }
                Message localMsg = new Message();
                localMsg.what = 0;
                localMsg.arg1 = deleteNoPic(bannerBeanList).size();
                mHandler.sendMessageDelayed(localMsg, 10000);
            }
            showCicle(0);
        } else {
            View view = View.inflate(HomePagerActivity.this, R.layout.layout_mainadvertisement, null);
            ImageView imageView = view.findViewById(R.id.iv_image);
            Glide.with(getApplicationContext()).load(R.mipmap.home_bg).into(imageView);
            viewContains.add(view);
            myPagerAdapter.notifyDataSetChanged();
        }
    }

    private void showCicle(int position) {
        if (viewContains.size() > 1) {
            llContent.removeAllViews();
            for (int i = 0; i < viewContains.size(); i++) {
                View view = LayoutInflater.from(HomePagerActivity.this).inflate(R.layout.layout_cicle, null);
                ImageView imageView = view.findViewById(R.id.iv_image);
                if (i == position) {
                    imageView.setImageResource(R.drawable.gray_cicle);
                } else {
                    imageView.setImageResource(R.drawable.white_cicle);
                }
                llContent.addView(view);
            }
        }
    }

    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case 0://开始轮播哦
                    if (mHandler.hasMessages(0)) {
                        mHandler.removeMessages(0);
                    }
                    currentPosition++;
                    if (currentPosition == msg.arg1) {
                        currentPosition = 0;
                    }
                    vpHome.setCurrentItem(currentPosition);
                    Message msgs = new Message();
                    msgs.what = 0;
                    msgs.arg1 = msg.arg1;
                    mHandler.sendMessageDelayed(msgs, 10000);
                    break;
                case 100:
                    CircleCrop circleCrop = new CircleCrop();
                    RequestOptions options = RequestOptions.bitmapTransform(circleCrop);
                    Glide.with(HomePagerActivity.this).asBitmap().load(R.mipmap.home_me).apply(options).into(new TransformationHomeUtils((ImageView) msg.obj, HomePagerActivity.this));
                    break;
                case 101:
                    NetErrorPop errorPop = new NetErrorPop(HomePagerActivity.this);
                    errorPop.showPop("");
                    break;
            }
        }
    };

    private List<BannerBean> deleteNoPic(List<BannerBean> bannerBeanList) {
        List<BannerBean> mBanner = new ArrayList<>();
        if (null != bannerBeanList && bannerBeanList.size() > 0) {
            for (int i = 0; i < bannerBeanList.size(); i++) {
                if (!StringUtils.isEmpty(bannerBeanList.get(i).getCover())) {
                    mBanner.add(bannerBeanList.get(i));
                }
            }
        }
        return mBanner;
    }

    private void setPagerListener() {
        vpHome.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                currentPosition = position;
                showCicle(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {
            }
        });
    }

    private class MyPagerAdapter extends PagerAdapter {
        @Override
        public int getCount() {
            return viewContains.size();
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
//                ((ViewPager) container).removeView(viewContains.get(position));
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            position %= viewContains.size();
            if (position < 0) {
                position = viewContains.size() + position;
            }
            View view = viewContains.get(position);
            // 如果View已经在之前添加到了一个父组件，则必须先remove，否则会抛出IllegalStateException。
            ViewParent vp = view.getParent();
            if (vp != null) {
                ViewGroup parent = (ViewGroup) vp;
                parent.removeView(view);
            }
            container.addView(view);
            return view;
        }

        @Override
        public int getItemPosition(Object object) {
            return super.getItemPosition(object);
        }
    }


    private void setPagerAdapter() {
        myPagerAdapter = new MyPagerAdapter();
        vpHome.setAdapter(myPagerAdapter);
    }


    class MyPageTransform implements ViewPager.PageTransformer {

        private static final float MIN_SCALE = 0.85f;
        private static final float MIN_ALPHA = 0.5f;

        public void transformPage(View view, float position) {
            int pageWidth = view.getWidth();
            int pageHeight = view.getHeight();

            Log.e("TAG", view + " , " + position + "");

            if (position < -1) { // [-Infinity,-1)
                // This page is way off-screen to the left.
                view.setAlpha(0);

            } else if (position <= 1) //a页滑动至b页 ； a页从 0.0 -1 ；b页从1 ~ 0.0
            { // [-1,1]
                // Modify the default slide transition to shrink the page as well
                float scaleFactor = Math.max(MIN_SCALE, 1 - Math.abs(position));
                float vertMargin = pageHeight * (1 - scaleFactor) / 2;
                float horzMargin = pageWidth * (1 - scaleFactor) / 2;
                if (position < 0) {
                    view.setTranslationX(horzMargin - vertMargin / 2);
                } else {
                    view.setTranslationX(-horzMargin + vertMargin / 2);
                }
                // Scale the page down (between MIN_SCALE and 1)
                view.setScaleX(scaleFactor);
                view.setScaleY(scaleFactor);

                // Fade the page relative to its size.
                view.setAlpha(MIN_ALPHA + (scaleFactor - MIN_SCALE)
                        / (1 - MIN_SCALE) * (1 - MIN_ALPHA));

            } else { // (1,+Infinity]
                // This page is way off-screen to the right.
                view.setAlpha(0);
            }
        }
    }


    @OnClick({R.id.ll_person, R.id.ll_homework, R.id.ll_libray, R.id.ll_listen, R.id.ll_gifts, R.id.ll_class, R.id.ll_personnel_management})
    public void onViewClicked(View view) {
        Intent mIntent = null;
        switch (view.getId()) {
            case R.id.ll_person:
                mIntent = new Intent(HomePagerActivity.this, MineInfoActivity.class);
                startActivity(mIntent);
                break;
            case R.id.ll_homework:
                mIntent = new Intent(HomePagerActivity.this, HomeworkListActivity.class);
                startActivity(mIntent);
                break;
            case R.id.ll_libray://0代表首页过去的   1代表磨耳朵 过去的
                mIntent = new Intent(HomePagerActivity.this, MoreReadingActivity.class);
                mIntent.putExtra("type", "0");
                startActivity(mIntent);
                break;
            case R.id.ll_listen:
                mIntent = new Intent(HomePagerActivity.this, GrindingEarsActivity.class);
                startActivity(mIntent);
                break;
            case R.id.ll_gifts:
                mIntent = new Intent(HomePagerActivity.this, GiftsListActivity.class);
                startActivity(mIntent);
                break;
            case R.id.ll_class:
                mIntent = new Intent(HomePagerActivity.this, ClassListActivity.class);
                startActivity(mIntent);
                break;
            case R.id.ll_personnel_management:
                //人员管理
                mIntent = new Intent(HomePagerActivity.this, PersonnelManagementActivity.class);
                startActivity(mIntent);
                break;
        }
    }
}
